package com.zhida84.Servlet;
/**
 * 
 * @author shazhengbo sunchangxing
 *
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.sun.glass.ui.CommonDialogs.Type;
import com.zhida84.Convert.DESJM;
import com.zhida84.Dao.RecruitDao;
import com.zhida84.Dao.ShowDetailDao;
import com.zhida84.Entity.RecruitTab;
import com.zhida84.Impl.RecruitImpl;
import com.zhida84.Impl.ShowDetailImpl;

/**
 * Servlet implementation class myparttimejob
 */
public class myparttimejob extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public myparttimejob() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		request.setCharacterEncoding("UTF-8");
		try {
			PrintWriter out = response.getWriter();
			Cookie[] cookies = request.getCookies();
			String userId=null;
			if (cookies == null) {
				return;
			}
			for (Cookie c : cookies) {
				if (c.getName().equals("userId"))// 依据cookies里面的手机
				{
					userId = c.getValue();
					break;
				}
			}
			ShowDetailDao recDao = new ShowDetailImpl();
			ResultSet rs=recDao.showCollectionByUserId(Integer.valueOf(userId));
			ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			while (rs.next()) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("jobName", rs.getString("jobName"));
				map.put("reType", rs.getString("reType"));
				map.put("recruitId", rs.getInt("recruitId"));
				map.put("collectionId", rs.getInt("collectionId"));
				list.add(map);
			}
			JSONArray ja = JSONArray.fromObject(list);
			out.print(ja);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
